<%@page
	import="com.meiya.common.string.StringUtil,java.io.StringReader,java.util.*"%>
<%@page import="com.chenlb.mmseg4j.*"%>
<%@page import="com.zhangwoo.service.word.analyser.WordAnalyser"%>
<%@page contentType="text/html;charset=utf-8"%>
<%
	String weixin_no_id = request.getParameter("weixin_no_id");
	String ques = java.net.URLDecoder.decode(
			request.getParameter("ques"), "utf-8");
	//System.out.print(ques);
	if (!StringUtil.isEmpty(weixin_no_id) && !StringUtil.isEmpty(ques)) {
		List<Object[]> keyRes = new com.meiya.common.simpledao.BaseDao()
				.query(com.meiya.common.simpledao.Config
						.getProps("sql2").toString()
						.replace("#keyword#", ques));
		System.out.print(com.meiya.common.simpledao.Config
				.getProps("sql2").toString()
				.replace("#keyword#", ques));
		if (keyRes !=null &&keyRes.size() > 0 && keyRes.get(0)!=null && !StringUtil.isEmpty(keyRes.get(0)[0].toString())) {
			out.print(keyRes.get(0)[0] + "~" + keyRes.get(0)[1]);
		} else {
			try {
				StringBuilder sb = new StringBuilder();
				MMSeg mmSeg = new MMSeg(new StringReader(ques),
						new ComplexSeg(
								com.chenlb.mmseg4j.Dictionary
										.getInstance()));
				Word word = null;
				boolean first = true;
				while ((word = mmSeg.next()) != null) {
					if (!(first)) {
						sb.append("|");
					}
					String w = word.getString();
					sb.append(w);
					first = false;
				}

				String[] strs = sb.toString().split("\\|");
				int curr_m = 0, curr_m_tmp = 0, curr_m_r = 0, curr_m_r_tmp = 0;
				Object[] result = null;
				List<Object[]> res = WordAnalyser
						.getAnswers(weixin_no_id);
				outer: for (Object[] os : res) {
					for (String s : strs) {
						if (os[0].toString().indexOf(s) > -1) { // 若数据库中的关键词包含当前分词
							curr_m_tmp = curr_m_tmp + s.length() * 100
									/ os[0].toString().length(); // 计算
							curr_m_r_tmp = curr_m_r_tmp + s.length()
									* 100 / ques.length();

							if (curr_m_tmp == 100
									&& curr_m_r_tmp == 100) {
								result = os;
								break outer;
							}
						}
					}

					if ((curr_m_tmp + curr_m_r_tmp) > (curr_m + curr_m_r)) {
						curr_m = curr_m_tmp;
						curr_m_r = curr_m_r_tmp;
						result = os;
					}
					curr_m_tmp = curr_m_r_tmp = 0;
				}
				if (result != null && result.length > 0)
					out.print(result[0] + "~" + result[1]);

			} catch (Exception e) {
				e.printStackTrace();
			}/* */
		}
	}
	//WordAnalyser
%>